<?php
namespace bee;
/**
 * @todo trebalo bi biti u libu
 * 
 */
global $app_USER;
$download = new download();
$download->SELECT(filter_var($_REQUEST['download_id'], FILTER_VALIDATE_INT));
if($download->expire ?: '2029-12-31' < date('Y-m-d H:i:s'))
{	denyUser();
}
if($download->client)
{	if($download->client != $app_USER->id)
	{	denyUser();
	}
}
if($download->group )
{	if(!isInGroup($app_USER->id, $download->group) && $download->group != -1)
	{	denyUser();
	}
}
if($download->org_id)
{	if($app_USER->org_id != $download->org_id)
	{	denyUser();
	}
}
header("Content-type: $download->content_type");
if(!@$_REQUEST['dont_download'])
{	header('Content-Disposition: attachment; filename="' . $download->down_name . '"');
}
readfile($download->file_name);

